﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class PasswordChange : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Session["isValid"].ToString().Equals("true"))
                Response.Redirect("login.aspx");
        }
        catch (Exception ex)
        {
            Exception ex2 = ex;
            Response.Redirect("login.aspx");
        }

        this.Label1.Text = "";

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataClassesDataContext dc = new DataClassesDataContext();
        User usr =
            (from u in dc.Users
             where u.Username.Equals(Session["username"])
             select u).Single();

        if (this.TextBox1.Text.Trim().Equals(usr.Password))
        {
            if (this.TextBox2.Text.Trim().Equals(this.TextBox3.Text.Trim()))
            {
                usr.Password = this.TextBox2.Text.Trim();
                dc.SubmitChanges();
                HttpContext.Current.Session["message"] = "Η αλλαγή συνθηματικού ήταν επιτυχής";
                Response.Redirect("default.aspx");
            }

            else
                HttpContext.Current.Session["message"] = "Απέτυχε η επιβεβαίωση του νέου συνθηματικού";
        }
        else
            HttpContext.Current.Session["message"] = "Λάθος συνθηματικό";

    }
}